	PRO GLOBALS,dir,PS=PS
; Usar leer_globals.pro
; Grafica la energia cineticas de protones, de electrones
; y magneticas parpendiculares y paralelas. Ademas las helicidades
; y la energia total.

leer_globals,dir,g,NN
leer_input,dir,N,nu,eta,eps,delta,dt,nstep,nstg,nstdat,nstk,nstp

t=fltarr(NN+1)
e_per_h=t ; hydrodynamic energy perpendicular
e_per_b=t ; magnetic energy perpendicular
e_per_e=t ; electron energy perpendicular

e_par_h=t ; hydrodynamic energy parallel
e_par_b=t ; magnetic energy parallel
e_par_e=t ; electron energy parallel

hel_p=t ; proton helicity
hel_e=t ; magnetic helicity
hel_c=t ; cross helicity (<u_perp.b_perp>)
j2 = t ; <jz^2> 
w2 = t; <w^2> 
e_t = t; energy total
uj = t; < u.j >

t(*)=g(0,0:NN)
e_per_h(*)=g(1,0:NN)
e_per_b(*)=g(2,0:NN)
e_per_e(*)=g(3,0:NN)
w2(*) = g(4,0:NN)
j2(*) = g(5,0:NN)
e_par_h(*)=g(8,0:NN)
e_par_b(*)=g(9,0:NN)
e_par_e(*)=g(10,0:NN)
hel_p(*)=g(12,0:NN)
hel_e(*)=g(11,0:NN)
hel_c(*)=g(7,0:NN)
uj=g(13,0:NN)

e_per_t = e_per_h + e_per_b + e_per_e
e_par_t = e_par_h + e_par_b + e_par_e
e_t = e_par_t + e_per_t
e_t = e_t/e_t(0)

coef = delta*eps/(1+delta)^0.5
ep = (e_per_h + e_per_e) + (e_par_h + e_par_e) + coef*uj/2
;if ep(0) ne 0.0 then ep = ep/ep(0)
ee = (e_per_h + e_per_e) + (e_par_h + e_par_e) - (coef/delta)*uj/2
;if ee(0) ne 0.0 then ee = ee/ee(0)
eb = e_par_b + e_per_b
;eb = eb/eb(0)

dE = max(e_t)-min(e_t) & nu_ef = dE/(j2+w2)
print,'======================================================================='
print, '|max(E_T)-min(E_T)| = ',dE
print,'======================================================================='

;save,file=dir+'e1.idl',t,e_t

perp = '!9x!n!3' ; perp symbol
para = '!9#!n!3' ; para symbol
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!p.multi = [0,1,1]
if not keyword_set(ps) then window,0,xs=600,ys=600
if keyword_set(ps) then begin
set_plot,'PS'
device,filename=dir+'energies_separate.eps',bits_per_pixel=8,/encapsulated,xs=15,ys=12
endif
plot,t,eb-eb(0),linestyle=3,xr=[0,2.0],yr=[-0.005,0.005],tit='Total (solid) Magnetic (.-) Proton (-) Electron (.)',ytit=' Energy',charsize=2.0
oplot,t,ee-ee(0),linestyle=1
oplot,t,ep-ep(0),linestyle=2
oplot,t,e_t-e_t(0),linestyle=0
if keyword_set(ps) then begin
device,/close
set_plot,'X'
endif

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!p.multi = 0
if not keyword_set(ps) then window,1,xs=600,ys=600
if keyword_set(ps) then begin
set_plot,'PS'
device,filename=dir+'ideal_invariants.eps',bits_per_pixel=8,/encapsulated,xs=15,ys=12
endif

!p.multi = [0,1,3]
max_yh = 1.2*max([max(hel_p), max(hel_e)])
min_yh = 1.2*min([min(hel_p), min(hel_e)])
plot,t,e_t,linestyle=0,tit='Total Energy',xr=[0,2.5],xsty=1,ysty=1,yr=[0.9,1.1],charsize=2.0
plot,t,hel_p,linestyle=0,tit='Proton Helicity',xr=[0,2.5],yr=[-1.1*abs(min(hel_p)),1.1*max(hel_p)],xsty=1,ysty=1,charsize=2.0
plot,t,hel_e,linestyle=0,xtit='Time',tit='Electron Helicity',xr=[0,2.5],yr=[-1.1*abs(min(hel_e)),1.1*max(hel_e)],xsty=1,ysty=1,charsize=2.0
if keyword_set(ps) then begin
device,/close
set_plot,'X'
endif

;!p.multi = 0
;if not keyword_set(ps) then window,2,xs=600,ys=600
;if keyword_set(ps) then begin
;set_plot,'PS'
;device,filename=dir+'eta_eff.eps',bits_per_pixel=8,/encapsulated,xs=15,ys=12
;endif
;plot,t,nu_ef,linestyle=0,xtit='Time',ytit='<j^2>+<w^2>',charsize=2.0,tit='eta efectivo',xr=[0,2.5]
;if keyword_set(ps) then begin
;device,/close
;set_plot,'X'
;endif
end
